package com.freemyleft.left.zapp.util;

import android.support.design.widget.TextInputEditText;

import java.util.regex.Pattern;

/**
 * Created by FreeMyleft on 2018/3/9.
 */

public class EditTextUtil {
    private final static String PHONE_PATTERN = "^1+[3578]+\\d{9}";//电话号正则
    private final static String EDIT_TEXT_PATTERN = "^[\\u4E00-\\u9FA5A-Za-z0-9]+$";
    private final static String YINHANGKA_PATTERN = "^([1-9]{1})(\\d{14}|\\d{18})$";
    private final static String A_Z_PATTERN = "[0-9A-Za-z] {0,20}";

    public static boolean Chekechejiahao(String a) {
        String[] array = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
        int length = a.length();
        if (length != 17) {
            return false;
        }
        char[] strChar = a.toCharArray();
        for (char as : strChar) {
            if (Character.isUpperCase(as) || Character.isDigit(as)) {
            } else {
                return Character.isUpperCase(as);
            }
        }
        return true;
    }

    public static boolean ChekPhoneNumber(String phoneNumber, TextInputEditText edittext) {
        boolean isPass = false;
        if (phoneNumber.isEmpty()) {
            edittext.setError("输入不能为空");
            isPass = false;
        } else if (!Pattern.matches(PHONE_PATTERN, phoneNumber)) {
            edittext.setError("输入格式不正确");
            isPass = false;
        } else {
            isPass = true;
        }
        return isPass;

    }

    public static boolean ChekYinghangka(String yinhangka, TextInputEditText edittext) {
        boolean isPass = false;
        if (yinhangka.isEmpty()) {
            edittext.setError("输入不能为空");
            isPass = false;
        } else if (!Pattern.matches(YINHANGKA_PATTERN, yinhangka)) {
            edittext.setError("输入格式不正确");
            isPass = false;
        } else {
            isPass = true;
        }
        return isPass;

    }

    public static boolean ChekText(String Text, TextInputEditText edittext) {
        boolean isPass = false;
        if (Text.isEmpty()) {
            edittext.setError("输入不能为空");
            isPass = false;
        } else if (!Pattern.matches(EDIT_TEXT_PATTERN, Text)) {
            edittext.setError("输入格式不正确");
            isPass = false;
        } else {
            isPass = true;
        }
        return isPass;

    }
    public static boolean ChekA_Z(String Text, TextInputEditText edittext) {
        boolean isPass = false;
        if (Text.isEmpty()) {
            edittext.setError("输入不能为空");
            isPass = false;
        } else if (!Pattern.matches(A_Z_PATTERN, Text)) {
            edittext.setError("输入格式不正确");
            isPass = false;
        } else {
            isPass = true;
        }
        return isPass;

    }


}
